local BulletSystem = Battle.CreateClass("BulletSystem")
Battle.BulletSystem = BulletSystem
local this = BulletSystem

function BulletSystem.OnCreate()
    ---@type Battle.Bullet[]
    this.bulletList = {}
    Battle.ClientBattle:RegisterUpdateCallback(this.Update)
end
function BulletSystem.OnDestroy()

end
---@param skill Battle.Skill
function BulletSystem.CreateBullet(bulletId,skill,targetId,pos,forward)
    local bullet = Battle.PoolMgr.GetBulletFromPool()
    local uniqueId = Battle.IDGenerator.GetId()
    bullet:Reset()
    bullet:SetTransfer(pos,forward)
    bullet:SetBullet(uniqueId,bulletId,skill,targetId)
    bullet:SetDamage(skill:CalcDamage(),skill.skillData.hurtType)
    this.AddBullet(bullet)
    bullet:Execute()

    return bullet
end
---@param bullet Battle.EffectBase
function BulletSystem.AddBullet(bullet)
    this.bulletList[bullet.id] = bullet
end
---@param bullet Battle.Bullet
function BulletSystem.DestroyBullet(bullet)
    if not bullet then return end
    this.bulletList[bullet.id] = nil
    bullet:OnDestroy()
    Battle.PoolMgr.ReturnBulletToPool(bullet)
end
function BulletSystem.GetBullet(bulletId)
    return this.bulletList[bulletId]
end
function BulletSystem.Update(dt)
    for k,v in pairs(this.bulletList) do
        v:Update(dt)
        if v:IsDie() then
            this.DestroyBullet(v)
        end
    end
end